package local_life_service

import (
	"blog/app/models"
	"blog/config"
	"blog/service"
	"blog/utils"
	"blog/utils/tools"
	"github.com/gin-gonic/gin"
)

// GetBanners 获取轮播图列表
func GetBanners(c *gin.Context) {
	var banners []models.Banner
	err := utils.MySqlDB.Model(&banners).Find(&banners).Error
	if err != nil {
		service.CommonCJsonReply(c, config.ERROR, "获取数据db失败")
		return
	}
	// 格式化处理图片链接
	for index, item := range banners {
		banners[index].Image = tools.ParseUrlImg(item.Image)
	}
	service.CommonCJsonReply(c, config.SUCCESS, banners)
}

// GetGridList 九宫格列表
func GetGridList(c *gin.Context) {
	var gridList []models.Category
	err := utils.MySqlDB.Model(&gridList).Find(&gridList).Error
	if err != nil {
		service.CommonCJsonReply(c, config.ERROR, "获取数据db失败")
		return
	}
	for index, item := range gridList {
		gridList[index].Icon = tools.ParseUrlImg(item.Icon)
	}
	service.CommonCJsonReply(c, config.SUCCESS, gridList)
}
